package com.jhhc.FloodForecast;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.jhhc.utils.ArrayAsList;
import com.jhhc.utils.JsonResult;
import com.jhhc.FloodForecast.BaseInfo.Pojo.BasinScheme;
import com.jhhc.FloodForecast.BaseInfo.Pojo.BasinSchemeInfo;
import com.jhhc.FloodForecast.BaseInfo.Pojo.ForecastScheme;
import com.jhhc.FloodForecast.BaseInfo.Pojo.ForecastSchemeInfo;
import com.jhhc.FloodForecast.BaseInfo.Pojo.ForecastStation;
import com.jhhc.FloodForecast.BaseInfo.Pojo.ForecastStationInfo;
import com.jhhc.FloodForecast.BaseInfo.Pojo.UpBorderInfo;
import com.jhhc.FloodForecast.BaseInfo.Service.*;
import com.jhhc.FloodForecast.ForecastModel.Pojo.ForecastModel;
import com.jhhc.FloodForecast.ForecastModel.Pojo.ForecastModelInfo;
import com.jhhc.FloodForecast.ForecastModel.Pojo.ForecastModelPar;
import com.jhhc.FloodForecast.ForecastModel.Pojo.ForecastModelp;
import com.jhhc.FloodForecast.ForecastModel.Service.*;
import com.jhhc.FloodForecast.OperationModel.Pojo.OpElementInfo;
import com.jhhc.FloodForecast.OperationModel.Pojo.OutOfData;
import com.jhhc.FloodForecast.OperationModel.Pojo.OutOfDataItems;
import com.jhhc.FloodForecast.OperationModel.Pojo.RsvrOpMode;
import com.jhhc.FloodForecast.OperationModel.Pojo.RsvrOpModeInfo;
import com.jhhc.FloodForecast.OperationModel.Service.*;
import com.jhhc.FloodForecast.Calculate.Condition.Pojo.CalculateCondition_B;
import com.jhhc.FloodForecast.Calculate.Condition.Pojo.CalculateCondition_M;
import com.jhhc.FloodForecast.Calculate.Condition.Pojo.Condition_M;
import com.jhhc.FloodForecast.Calculate.Condition.Pojo.ForecastModifyData;
import com.jhhc.FloodForecast.Calculate.Condition.Pojo.ModifyData;
import com.jhhc.FloodForecast.Calculate.Condition.Pojo.Scheme;
import com.jhhc.FloodForecast.Calculate.Condition.Service.*;
import io.swagger.annotations.ApiOperation;
@RestController
@RequestMapping(value = "FloodForecast")
@Api(value="FloodForecastController",tags={"洪水预报"})
public class FloodForecastController {
    @Autowired
    private BasinSchemeService BasinSchemeService;
    @Autowired
    private ForecastSchemeService ForecastSchemeService;
    @Autowired
    private ForecastStationService ForecastStationService;
    @Autowired
    private OutOfDataService OutOfDataService;
    @Autowired
    private SchemeService SchemeService;
    @Autowired
    private Condition_MService Condition_MService;
    @Autowired
    private ForecastModelService forecastModelService;
    @Autowired
    private ForecastModelpService forecastModelpService;
    @Autowired
    private RsvrOpModeService rsvrOpModeService;
    @Autowired
    private ModifyDataService ModifyDataService;

    //查询预报模型列表
    @ApiOperation("查询预报模型列表")
    @RequestMapping(value = "ForecastModel/GetModel", method = RequestMethod.GET)
    private JsonResult GetModel() {
        JsonResult jsonResult = new JsonResult();

        List<ForecastModelInfo> forecastModelInfoList = new ArrayList<ForecastModelInfo>();//定义ForecastModelInfo返回类型集合

        List<ForecastModel> forecastModelList = forecastModelService.selectAll();

        for (int i = 0; i < forecastModelList.size(); i++) {
            ForecastModelInfo forecastModelInfo = new ForecastModelInfo();
            if (forecastModelList.get(i).getModelid() != null) {
                forecastModelInfo.setModelId(forecastModelList.get(i).getModelid());
            }
            if (forecastModelList.get(i).getModelnm() != null) {
                forecastModelInfo.setModelName(forecastModelList.get(i).getModelnm());
            }
            if (forecastModelList.get(i).getModelabb() != null) {
                forecastModelInfo.setModelABB(forecastModelList.get(i).getModelabb());
            }
            if (forecastModelList.get(i).getModeltype() != null) {
                forecastModelInfo.setModelType(forecastModelList.get(i).getModeltype());
            }
            if (forecastModelList.get(i).getYmdhm() != null) {
                forecastModelInfo.setYMDHM(forecastModelList.get(i).getYmdhm());
            }
            if (forecastModelList.get(i).getRemark() != null) {
                forecastModelInfo.setRemark(forecastModelList.get(i).getRemark());
            }
            forecastModelInfoList.add(forecastModelInfo);
        }

        jsonResult.setStatusCode(200);
        jsonResult.setSucceeded(true);
        jsonResult.setData(forecastModelInfoList);

        return jsonResult;
    }

    //查询模型参数信息
    @ApiOperation("查询模型参数信息")
    @RequestMapping(value = "ForecastModel/GetModelParamInfo", method = RequestMethod.GET)
    private JsonResult GetModelParamInfo() {
        JsonResult jsonResult = new JsonResult();

        List<ForecastModelPar> forecastModelParsList = new ArrayList<ForecastModelPar>();

        List<ForecastModelp> forecastModelpsList = forecastModelpService.selectAll();

        for (int i = 0; i < forecastModelpsList.size(); i++) {
            ForecastModelPar forecastModelPar = new ForecastModelPar();
            if (forecastModelpsList.get(i).getModelid() != null) {
                forecastModelPar.setModelId(forecastModelpsList.get(i).getModelid());
            }
            if (forecastModelpsList.get(i).getParid() != null) {
                forecastModelPar.setParamId(forecastModelpsList.get(i).getParid());
            }
            if (forecastModelpsList.get(i).getParnm() != null) {
                forecastModelPar.setParamName(forecastModelpsList.get(i).getParnm());
            }
            if (forecastModelpsList.get(i).getParabb() != null) {
                forecastModelPar.setParamABB(forecastModelpsList.get(i).getParabb());
            }
            if (forecastModelpsList.get(i).getParlimits() != null) {
                forecastModelPar.setParamLimits(forecastModelpsList.get(i).getParlimits());
            }
            forecastModelParsList.add(forecastModelPar);
        }

        jsonResult.setStatusCode(200);
        jsonResult.setSucceeded(true);
        jsonResult.setData(forecastModelParsList);
        return jsonResult;
    }

    //查询水库调度模式信息
    @ApiOperation("查询水库调度模式信息")
    @RequestMapping(value = "OperationModel/GetOpModeInfo", method = RequestMethod.GET)
    private JsonResult GetOpModeInfo(@RequestParam Integer ProjectId) {
        JsonResult jsonResult = new JsonResult();
        List<RsvrOpModeInfo> rsvrOpModeInfoList = new ArrayList<RsvrOpModeInfo>();
        List<RsvrOpMode> rsvrOpModesList = rsvrOpModeService.selectById(ProjectId);
        for (int i = 0; i < rsvrOpModesList.size(); i++) {
            RsvrOpModeInfo rsvrOpModeInfo = new RsvrOpModeInfo();

            if (rsvrOpModesList.get(i).getPid() != null) {
                rsvrOpModeInfo.setProjectId(rsvrOpModesList.get(i).getPid());
            }
            if (rsvrOpModesList.get(i).getRsvrnm() != null) {
                rsvrOpModeInfo.setRsvrName(rsvrOpModesList.get(i).getRsvrnm());
            }
            if (rsvrOpModesList.get(i).getRsopmodel() != null) {
                rsvrOpModeInfo.setRsvrOperationModel(rsvrOpModesList.get(i).getRsopmodel());
            }
            if (rsvrOpModesList.get(i).getRsopmodelorder() != null) {
                rsvrOpModeInfo.setRsvrOperationModelOrder(rsvrOpModesList.get(i).getRsopmodelorder());
            }
            if (rsvrOpModesList.get(i).getOpelements() != null) {
                String[] opelement = rsvrOpModesList.get(i).getOpelements().split(";");
                for (int j = 0; j < opelement.length; j++) {
                    String[] opelements = opelement[j].split(",");
                    OpElementInfo OpElementInfo = new OpElementInfo();
                    OpElementInfo.setElementName(opelements[0]);
                    OpElementInfo.setElementParam(opelements.length > 1 ? opelements[1] : null);
                    rsvrOpModeInfo.setOperationElements(OpElementInfo);
                }
            }
            if (rsvrOpModesList.get(i).getParameters() != null) {
                rsvrOpModeInfo.setParameters(rsvrOpModesList.get(i).getParameters());
            }
            if (rsvrOpModesList.get(i).getRemark() != null) {
                rsvrOpModeInfo.setRemark(rsvrOpModesList.get(i).getRemark());
            }
            rsvrOpModeInfoList.add(rsvrOpModeInfo);
        }

        jsonResult.setStatusCode(200);
        jsonResult.setSucceeded(true);
        jsonResult.setData(rsvrOpModeInfoList);
        return jsonResult;

    }

    //查询预报流域
    @ApiOperation("查询预报流域概化信息")
    @RequestMapping(value = "BaseInfo/GetBasinSchemeInfo", method = RequestMethod.GET)
    private JsonResult GetBasinSchemeInfo(@RequestParam Integer ProjectId) {
        JsonResult jsonResult = new JsonResult();
        System.out.println(ProjectId);
        List<BasinSchemeInfo> BasinSchemeInfoList = new ArrayList<BasinSchemeInfo>();

        List<BasinScheme> list = BasinSchemeService.selectByProjectId(ProjectId);
        for (int i = 0; i < list.size(); i++) {
            BasinSchemeInfo BasinSchemeInfo = new BasinSchemeInfo();
            BasinSchemeInfo.setProjectId(list.get(i).getPid());
            BasinSchemeInfo.setBasinSchemeId(list.get(i).getBschemeid());
            BasinSchemeInfo.setBasinSchemeName(list.get(i).getBschemenm());
            BasinSchemeInfo.setBasin(list.get(i).getBasin());
            BasinSchemeInfo.setBasinOrder(list.get(i).getBasinorder());
            //测试获取
            System.out.println(BasinSchemeInfo.getBasin() + "basin");
            System.out.println(BasinSchemeInfo.getBasinOrder() + "order");
            //	boolean res1 = list.get(i).getUpb().equals(null);
            //	System.out.println(res1);

            //就这块

            if (list.get(i).getUpb() != null) {
                String str = list.get(i).getUpb();
                List<String> strlist = ArrayAsList.ArrayList(str);
                UpBorderInfo upb = new UpBorderInfo();
                //切割
                boolean res = strlist.get(0).equals("");
                if (res == true) {
                    upb.setBorderName("");
                    upb.setStationName("");
                    upb.setStationId("");
                } else {
                    System.out.println(strlist.size() + "strlist长度");
                    for (int j = 0; j < strlist.size(); j++) {
                        upb.setBorderName(strlist.get(0));
                        upb.setStationName(strlist.get(1));
                        upb.setStationId(strlist.get(2));
                    }
                }
                BasinSchemeInfo.setUpBorderInfoList(upb);
            } else {
                UpBorderInfo upb = new UpBorderInfo();
                upb.setBorderName(null);
                upb.setStationName(null);
                upb.setStationId(null);
                BasinSchemeInfo.setUpBorderInfoList(upb);
            }
            if (list.get(i).getHydroareas() != null) {
                List<String> hydroAreaList = ArrayAsList.ArrayList(list.get(i).getHydroareas());
                BasinSchemeInfo.setHydroAreaList(hydroAreaList);
            }
            if (list.get(i).getRsvrs() != null) {
                List<String> rsvrList = ArrayAsList.ArrayList(list.get(i).getRsvrs());
                BasinSchemeInfo.setRsvrList(rsvrList);
            }
            if (list.get(i).getWfareas() != null) {
                List<String> WFAREAList = ArrayAsList.ArrayList(list.get(i).getWfareas());
                BasinSchemeInfo.setWFAREAList(WFAREAList);
            }
            BasinSchemeInfoList.add(BasinSchemeInfo);
        }


        jsonResult.setStatusCode(200);
        jsonResult.setSucceeded(true);
        jsonResult.setData(BasinSchemeInfoList);
        return jsonResult;
    }

    //查询预报方案
    @ApiOperation("查询预报方案信息")
    @RequestMapping(value = "BaseInfo/GetSchemeInfo", method = RequestMethod.GET)
    private JsonResult GetSchemeInfo(@RequestParam Integer ProjectId) {
        JsonResult jsonResult = new JsonResult();
        System.out.println(ProjectId);
        List<ForecastScheme> list = ForecastSchemeService.selectByProjectId(ProjectId);
        List<ForecastSchemeInfo> ForecastSchemeInfoList = new ArrayList<ForecastSchemeInfo>();
        ForecastSchemeInfo ForecastSchemeInfo = new ForecastSchemeInfo();

        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getPid() != null) {
                ForecastSchemeInfo.setProjectId(list.get(i).getPid());
            }
            if (list.get(i).getFschemenm() != null) {
                ForecastSchemeInfo.setForecastSchemeName(list.get(i).getFschemenm());
            }
            if (list.get(i).getFschemetype() != null) {
                ForecastSchemeInfo.setForecastSchemeType(list.get(i).getFschemetype());
            }
            if (list.get(i).getFschemeid() != null) {
                ForecastSchemeInfo.setForecastSchemeId(list.get(i).getFschemeid());
            }
            if (list.get(i).getBschemeid() != null) {
                ForecastSchemeInfo.setBasinSchemeId(list.get(i).getBschemeid());
            }
            if (list.get(i).getFschemeorder() != null) {
                ForecastSchemeInfo.setForecastSchemeOrder(list.get(i).getFschemeorder());
            }
            if (list.get(i).getBasinmodel() != null) {
                ForecastSchemeInfo.setBasinModel(list.get(i).getBasinmodel());
            }
            if (list.get(i).getRivermodel() != null) {
                ForecastSchemeInfo.setRiverModel(list.get(i).getRivermodel());
            }
            if (list.get(i).getRsvrmodel() != null) {
                ForecastSchemeInfo.setRsvrModel(list.get(i).getRsvrmodel());
            }
            if (list.get(i).getCalbackt() != null) {
                ForecastSchemeInfo.setCalculateBackDay(list.get(i).getCalbackt());
            }
            if (list.get(i).getCalinterval() != null) {
                ForecastSchemeInfo.setCalculateInterval(list.get(i).getCalinterval());
            }
            if (list.get(i).getCalmaxt() != null) {
                ForecastSchemeInfo.setCalculateMaxHour(list.get(i).getCalmaxt());
            }
            if (list.get(i).getWfdep() != null) {
                ForecastSchemeInfo.setWFDEP(list.get(i).getWfdep());
            }
            if (list.get(i).getSchemeinfo() != null) {
                ForecastSchemeInfo.setSchemeInfo(list.get(i).getSchemeinfo());
            }
            if (list.get(i).getRemark() != null) {
                ForecastSchemeInfo.setRemark(list.get(i).getRemark());
            }
            ForecastSchemeInfoList.add(ForecastSchemeInfo);
        }
        jsonResult.setStatusCode(200);
        jsonResult.setSucceeded(true);
        jsonResult.setData(ForecastSchemeInfoList);


        return jsonResult;
    }

    //查询预报站点
    @ApiOperation("查询预报站点信息")
    @RequestMapping(value = "BaseInfo/GetStationInfo", method = RequestMethod.GET)
    private JsonResult GetStationInfo(@RequestParam Integer ProjectId) {
        JsonResult jsonResult = new JsonResult();
        System.out.println(ProjectId);
        List<ForecastStation> list = ForecastStationService.selectByProjectId(ProjectId);
        List<ForecastStationInfo> forecastStationInfoList = new ArrayList<ForecastStationInfo>();
        ForecastStationInfo ForecastStationInfo = new ForecastStationInfo();

        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getPid() != null) {
                ForecastStationInfo.setProjectId(list.get(i).getPid());
            }
            if (list.get(i).getFschemeid() != null) {
                ForecastStationInfo.setForecastSchemeId(list.get(i).getFschemeid());
            }
            if (list.get(i).getFstnm() != null) {
                ForecastStationInfo.setForecastStationName(list.get(i).getFstnm());
            }
            if (list.get(i).getFstcd() != null) {
                ForecastStationInfo.setForecastStationId(list.get(i).getFstcd());
            }
            if (list.get(i).getFsttp() != null) {
                ForecastStationInfo.setForecastStationType(list.get(i).getFsttp());
            }
            if (list.get(i).getFstationorder() != null) {
                ForecastStationInfo.setForecastStationOrder(list.get(i).getFstationorder());
            }
            if (list.get(i).getHydroareanm() != null) {
                ForecastStationInfo.setHydroAreaName(list.get(i).getHydroareanm());
            }
            if (list.get(i).getFitem() != null) {
                ForecastStationInfo.setForecastItem(list.get(i).getFitem());
            }
            if (list.get(i).getFnums() != null) {
                ForecastStationInfo.setForecastNumbers(list.get(i).getFnums());
            }

            if (list.get(i).getHnnm() != null) {
                ForecastStationInfo.setHNNM(list.get(i).getHnnm());
            }
            if (list.get(i).getRvnm() != null) {
                ForecastStationInfo.setRVNM(list.get(i).getRvnm());
            }
            if (list.get(i).getAdmauth() != null) {
                ForecastStationInfo.setADMAG(list.get(i).getAdmauth());
            }
            if (list.get(i).getObsnet() != null) {
                ForecastStationInfo.setOBSNET(list.get(i).getObsnet());
            }
            if (list.get(i).getObsstnm() != null) {
                ForecastStationInfo.setObservedStationName(list.get(i).getObsstnm());
            }
            if (list.get(i).getObsstcd() != null) {
                ForecastStationInfo.setObservedStationId(list.get(i).getObsstcd());
            }
            if (list.get(i).getObsitem() != null) {
                ForecastStationInfo.setObservedItem(list.get(i).getObsitem());
            }
            if (list.get(i).getZqrlnm() != null) {
                ForecastStationInfo.setZQRLNM(list.get(i).getZqrlnm());
            }
            if (list.get(i).getAlarmindex() != null) {
                ForecastStationInfo.setALARMINDEX(list.get(i).getAlarmindex());
            }
            if (list.get(i).getRelationStations() != null) {
                ForecastStationInfo.setRelation_HydroAreaS(list.get(i).getRelationHydroareas());
            }
            if (list.get(i).getRelationStations() != null) {
                ForecastStationInfo.setRelation_Stations(list.get(i).getRelationStations());
            }
			
			/*
			 * 	private List<String>	Relation_ForecastUpperPStation;
				private List<String>	Relation_ForecastBasinPStation;
				private List<String>	BOrder_UpperZQStation;
				private List<String>	BOrder_BasinZQStation;
			 */
            if (list.get(i).getShow() != null) {
                ForecastStationInfo.setShow(list.get(i).getShow());
            }
            if (list.get(i).getCalculate() != null) {
                ForecastStationInfo.setCalculate(list.get(i).getCalculate());
            }
            if (list.get(i).getAlarmindex() != null) {
                ForecastStationInfo.setRelation_ZQS(list.get(i).getAlarmindex());
            }
            if (list.get(i).getForecastpublish() != null) {
                ForecastStationInfo.setForecastStaionPublish(list.get(i).getForecastpublish());
            }
            if (list.get(i).getForecastpublishcode() != null) {
                ForecastStationInfo.setForecastStaionPublishCode(list.get(i).getForecastpublishcode());
            }
            if (list.get(i).getForecaststatus() != null) {
                ForecastStationInfo.setForecastStaionStatus(list.get(i).getForecaststatus());
            }
            if (list.get(i).getRemark() != null) {
                ForecastStationInfo.setRemark(list.get(i).getRemark());
            }

            if (list.get(i).getRelationFps() != null) {
                String[] str = list.get(i).getRelationFps().split("|");
                if (str.length == 2) {
                    ForecastStationInfo.setRelation_ForecastUpperPStation(Arrays.asList(str[0].split(",")));
                    ForecastStationInfo.setRelation_ForecastBasinPStation(Arrays.asList(str[1].split(",")));
                }

            }
            if (list.get(i).getRelationZqs() != null) {
                String[] str = list.get(i).getRelationZqs().split("|");
                if (str.length == 2) {
                    ForecastStationInfo.setBOrder_UpperZQStation(Arrays.asList(str[0].split(",")));
                    ForecastStationInfo.setBOrder_BasinZQStation(Arrays.asList(str[1].split(",")));
                }

            }


        }

        forecastStationInfoList.add(ForecastStationInfo);


        jsonResult.setStatusCode(200);
        jsonResult.setSucceeded(true);
        jsonResult.setData(forecastStationInfoList);
        return jsonResult;

    }

    //查询出库数据项信息
    @ApiOperation("查询出库数据项信息")
    @RequestMapping(value = "OperationModel/GetDataInfoForOutQ", method = RequestMethod.GET)
    private JsonResult GetDataInfoForOutQ(@RequestParam String ProjectId, @RequestParam String STCD, @RequestParam int DataItem) {
        JsonResult jsonResult = new JsonResult();
        System.out.println(ProjectId);
        List<OutOfData> list = OutOfDataService.selectBy(STCD, ProjectId);
        List<OutOfDataItems> OutOfDataItemsList = new ArrayList<OutOfDataItems>();
        //DATADICTIONARY  DATADICTIONARY  = new  DATADICTIONARY();

        System.out.println(list.size());
        for (int i = 0; i < list.size(); i++) {
            OutOfDataItems OutOfDataItems = new OutOfDataItems();
            if (list.get(i).getStcd() != null) {
                OutOfDataItems.setStationId(list.get(i).getStcd());
            }
            if (list.get(i).getAliasname() != null) {
                OutOfDataItems.setName(list.get(i).getAliasname());
            } else {
                OutOfDataItems.setName(list.get(i).getDATADICTIONARY().getDataname());
            }
            if (list.get(i).getDefaultvalue() != null) {
                OutOfDataItems.setDEFAULTVALUE(list.get(i).getDefaultvalue());
            }
            if (list.get(i).getDunit() != null) {
                OutOfDataItems.setDUNIT(list.get(i).getDunit());
            }
            if (list.get(i).getFprmula() != null) {
                OutOfDataItems.setFPRMULA(list.get(i).getFprmula());
            }
            if (list.get(i).getDataorder() != null) {
                OutOfDataItems.setDATAORDER(list.get(i).getDataorder());
            }

            OutOfDataItemsList.add(OutOfDataItems);

        }


        jsonResult.setStatusCode(200);
        jsonResult.setSucceeded(true);
        jsonResult.setData(OutOfDataItemsList);


        return jsonResult;
    }

    //查询预报参数方案信息
    @ApiOperation("查询预报参数方案信息")
    @RequestMapping(value = "Calculate/Condition/GetScheme", method = RequestMethod.GET)
    private JsonResult GetScheme(@RequestParam int ProjectId, @RequestParam List<String> UserIdList) {
        JsonResult jsonResult = new JsonResult();
        String UserId = null;
        String ConditionId = null;
        System.out.println(ProjectId);
        for (int i = 0; i < UserIdList.size(); i++) {
            UserId = UserIdList.get(0);
            ConditionId = UserIdList.get(1);
        }
        List<Scheme> list = SchemeService.selectByProjectId(ProjectId, UserId, ConditionId);
        List<CalculateCondition_B> CalculateCondition_BList = new ArrayList<CalculateCondition_B>();
        CalculateCondition_B CalculateCondition_B = new CalculateCondition_B();

        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getPid() != null) {
                CalculateCondition_B.setProjectId(list.get(i).getPid());
            }
            if (list.get(i).getUserid() != null) {
                CalculateCondition_B.setUserId(list.get(i).getUserid());
            }
            if (list.get(i).getFschemeid() != null) {
                CalculateCondition_B.setForecastSchemeId(list.get(i).getFschemeid());
            }
            if (list.get(i).getConditionid() != null) {
                CalculateCondition_B.setConditionId(list.get(i).getConditionid());
            }
            if (list.get(i).getConditionnm() != null) {
                CalculateCondition_B.setConditionName(list.get(i).getConditionnm());
            }
            if (list.get(i).getHydroarea() != null) {
                CalculateCondition_B.setHydroAreaParam(list.get(i).getHydroarea());
            }
            if (list.get(i).getRsvr() != null) {
                CalculateCondition_B.setRsvrParam(list.get(i).getRsvr());
            }
            if (list.get(i).getRiver() != null) {
                CalculateCondition_B.setRiverParam(list.get(i).getRiver());
            }
            if (list.get(i).getDike() != null) {
                CalculateCondition_B.setDike(list.get(i).getDike());
            }
            if (list.get(i).getRemark() != null) {
                CalculateCondition_B.setRemark(list.get(i).getRemark());
            }
            if (list.get(i).getPid() != null) {
                CalculateCondition_B.setFlag(list.get(i).getFlag());
            }

        }
        CalculateCondition_BList.add(CalculateCondition_B);


        jsonResult.setStatusCode(200);
        jsonResult.setSucceeded(true);
        jsonResult.setData(CalculateCondition_BList);
        return jsonResult;
    }

    //删除预报参数方案信息
    @ApiOperation("删除预报参数方案")
    @RequestMapping(value = "Calculate/Condition/DeleteScheme", method = RequestMethod.DELETE)
    private JsonResult DeleteScheme(@RequestParam int ProjectId, @RequestParam String UserId, @RequestParam String ForecastSchemeId, @RequestParam String ConditionId) {
        JsonResult jsonResult = new JsonResult();
        boolean res = true;
        int a = SchemeService.DeleteScheme(ProjectId, UserId, ForecastSchemeId, ConditionId);

        if (a > 0) {

            jsonResult.setStatusCode(200);
            jsonResult.setSucceeded(true);
            jsonResult.setData(res);
        }

        return jsonResult;

    }

    //插入预报参数方案信息
    @ApiOperation("插入预报参数方案信息")
    @RequestMapping(value = "Calculate/Condition/InsertScheme/{CalculateCondition_B}", method = RequestMethod.POST)
    private JsonResult InsertScheme(@RequestBody CalculateCondition_B calCondition) {
        JsonResult jsonResult = new JsonResult();
        Scheme scheme = new Scheme();
        boolean res = calCondition.getUserId().equals("0");
        System.out.println("" + res);
        if (res == false) {
            scheme.setPid(calCondition.getProjectId());
            if (calCondition.getUserId() != null) {
                scheme.setUserid(calCondition.getUserId());
            }
            if (calCondition.getForecastSchemeId() != null) {
                scheme.setFschemeid(calCondition.getForecastSchemeId());
            }
            if (calCondition.getConditionId() != null) {
                scheme.setConditionid(calCondition.getConditionId());
            }
            if (calCondition.getConditionName() != null) {
                scheme.setConditionnm(calCondition.getConditionName());
            }
            if (calCondition.getHydroAreaParam() != null) {
                scheme.setHydroarea(calCondition.getHydroAreaParam());
            }
            if (calCondition.getRsvrParam() != null) {
                scheme.setRsvr(calCondition.getRsvrParam());
            }
            if (calCondition.getRiverParam() != null) {
                scheme.setRsvr(calCondition.getRiverParam());
            }
            if (calCondition.getDike() != null) {
                scheme.setDike(calCondition.getDike());
            }
            if (calCondition.getRemark() != null) {
                scheme.setRemark(calCondition.getRemark());
            }
            if (calCondition.getFlag() != null) {
                if (calCondition.getFlag().equals("Y")) {
                    String flag = "N";
                    SchemeService.updateBy(flag);
                } else {
                    scheme.setFlag(calCondition.getFlag());
                }
            }


            int a = SchemeService.InsertScheme(scheme);
            if (a > 0) {
                res = true;
                jsonResult.setStatusCode(200);
                jsonResult.setSucceeded(true);
                jsonResult.setData(res);
            } else {
                res = false;
                jsonResult.setStatusCode(200);
                jsonResult.setSucceeded(true);
                jsonResult.setData(res);
            }

        }

        return jsonResult;
    }

    //设置默认参数方案（排他）
    @ApiOperation("设置默认参数方案（排他）")
    @RequestMapping(value = "Calculate/Condition/SetDefaultScheme", method = RequestMethod.PUT)
    private JsonResult SetDefaultScheme(@RequestParam int ProjectId, @RequestParam String UserId, @RequestParam String ForecastSchemeId, @RequestParam String ConditionId) {
        JsonResult jsonResult = new JsonResult();
        //UserId=0 系统级  else 用户级
        //对于用户级方案，设置当前为Y，设置其他用户级方案为N；
        //对于系统级方案，本身不做修改，修改其他所有用户级方案为N

        if (UserId.equals("0") && UserId.equals("")) {//系统级方案
            int a = SchemeService.updateBy("N"); //修改其他所有用户级方案为N
            if (a > 0) {

                jsonResult.setStatusCode(200);
                jsonResult.setSucceeded(true);
                jsonResult.setData(true);
            } else {
                jsonResult.setStatusCode(200);
                jsonResult.setSucceeded(true);
                jsonResult.setData(false);
            }
        } else { //用户级方案
            int a = SchemeService.updateBy("N");//设置其他用户级方案为N；
            int b = SchemeService.UpdateProjectId(ProjectId, UserId, ForecastSchemeId, ConditionId);//设置当前为Y
            if (a > 0 && b > 0) {
                jsonResult.setStatusCode(200);
                jsonResult.setSucceeded(true);
                jsonResult.setData(false);
            }
        }


        return jsonResult;
    }

    //保存预报计算参数方案（_M表）
    @ApiOperation("保存预报计算参数方案（_M表）")
    @RequestMapping(value = "Calculate/Condition/InsertCalculateCondition{calCondition_M}", method = RequestMethod.POST)
    private JsonResult InsertCalculateCondition(@RequestBody CalculateCondition_M calCondition_M) {
        JsonResult jsonResult = new JsonResult();
        Condition_M Condition_M = new Condition_M();
        if (calCondition_M.getCalculateSchemeId() != null) {
            Condition_M.setCschemeid(calCondition_M.getCalculateSchemeId());
        }

        if (calCondition_M.getHydroAreaParam() != null) {
            Condition_M.setHydroarea(calCondition_M.getHydroAreaParam());
        }
        if (calCondition_M.getRsvrParam() != null) {
            Condition_M.setRsvr(calCondition_M.getRsvrParam());
        }
        if (calCondition_M.getRiverParam() != null) {
            Condition_M.setRiver(calCondition_M.getRiverParam());
        }
        if (calCondition_M.getDike() != null) {
            Condition_M.setDike(calCondition_M.getDike());
        }
        if (calCondition_M.getRemark() != null) {
            Condition_M.setRemark(calCondition_M.getRemark());
        }

        int a = Condition_MService.InsertCalculateCondition(Condition_M);

        if (a > 0) {
            jsonResult.setStatusCode(200);
            jsonResult.setSucceeded(true);
            jsonResult.setData(true);
        } else {
            jsonResult.setStatusCode(200);
            jsonResult.setSucceeded(true);
            jsonResult.setData(false);
        }
        return jsonResult;
    }

    //保存预报交互数据
    @ApiOperation("保存预报交互数据 ")
    @RequestMapping(value = "Calculate/Condition/InsertModifyData{ModifyDataList }", method = RequestMethod.POST)
    private JsonResult InsertModifyData(@RequestBody List<ForecastModifyData> ModifyDataList) {
        JsonResult jsonResult = new JsonResult();
        ModifyData ModifyData = new ModifyData();
        for (int i = 0; i < ModifyDataList.size(); i++) {
            ModifyData.setCschemeid(ModifyDataList.get(i).getCalculateSchemeId());
            ModifyData.setdStnm(ModifyDataList.get(i).getD_STNM());
            ModifyData.setdType(ModifyDataList.get(i).getD_TYPE());
            ModifyData.setdTime(ModifyDataList.get(i).getD_TIME());
            ModifyData.setRemark(ModifyDataList.get(i).getRemark());
            ModifyData.setdItem(ModifyDataList.get(i).getD_ITEM());
        }
        int res = ModifyDataService.InsertModifyData(ModifyData);
        if (res > 0) {
            jsonResult.setStatusCode(200);
            jsonResult.setSucceeded(true);
            jsonResult.setData(true);
        } else {
            jsonResult.setStatusCode(200);
            jsonResult.setSucceeded(true);
            jsonResult.setData(false);
        }

        return jsonResult;
    }
}
